package logic;

import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.scene.Node;

public abstract class NodeController extends DelayedController {
	
	private static final long serialVersionUID = 1L;
	
	protected Node node;
	
	public NodeController(float updateDelay, Node node) {
		super(updateDelay);
		this.node = node;
	}
	
	protected void rotateTo(Vector3f pos, float amount, boolean invert) {
		if(pos == null || amount == 0f) return;
		Quaternion oldRot = node.getLocalRotation().clone();
		
		node.lookAt(pos, Vector3f.UNIT_Y);
		Quaternion targetRot = node.getLocalRotation().clone();
		
		node.getLocalRotation().set(oldRot);
		
		if(invert) targetRot.inverseLocal();
		node.getLocalRotation().slerp(targetRot, amount);
	}
}